package chenji.yourticket.inventory;

import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import chenji.yourticket.Main;
import chenji.yourticket.inventory.InventoryManager.OpeningInventoryType;

/**
 * @author ChenJi Copyright (c) 2016 ChenJi. All rights reserved.
 */

public abstract class SimpleInventory {
	private Player p;
	private Inventory i;
	private short data;
	private String title;
	private int line;
	private final int[] slot6 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 44, 45, 46, 47, 48,
			49, 50, 51, 52, 53 };
	private final int[] slot5 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 35, 36, 37, 38, 39, 40, 41,
			42, 43, 44 };
	private final int[] slot4 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 26, 27, 28, 29, 30, 31, 32, 33, 34,
			35 };
	private final int[] slot3 = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };

	public SimpleInventory(Player p, short data, String title, int line) {
		this.title = title;
		this.p = p;
		this.data = data;
		this.line = line;
		if (this.line == 0) {
			this.line = 3;
		}

		this.loadInventory();


	}

	public void openInventory(OpeningInventoryType p) {
		this.p.closeInventory();
		Main.getInventoryManager().openInventory(this.p, this.i,p);
		

	}

	public Inventory getInventory() {
		return this.i;
	}

	private void loadInventory() {
		i = Bukkit.createInventory(p, line * 9, title);

		ItemStack ia = new ItemStack(Material.STAINED_GLASS_PANE, 1, data);

		int[] slot = this.slot3;
		switch (line) {
		case 6:
			slot = this.slot6;
			break;
		case 5:
			slot = this.slot5;
			break;
		case 4:
			slot = this.slot4;
			break;
		case 3:
			slot = this.slot3;
			break;
		}
		ItemMeta m = ia.getItemMeta();
		m.setDisplayName(" ");
		ia.setItemMeta(m);
		for (int i : slot) {
			this.i.setItem(i, ia);
		}
	}

	public abstract void installItemStack();

}
